<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!--select2-->

    <!--zTree css-->

    <jsp:include page="../page/public.jsp"></jsp:include>
    <link rel="stylesheet" href="/resource/plugins/validator/jquery.validator.css">

</head>

<body class="sidebar-mini skin-blue-light fixed">
<!-- Site wrapper -->
<div class="wrapper">
    <jsp:include page="../page/header.jsp"></jsp:include>
    <jsp:include page="../page/left-sidebar.jsp"></jsp:include>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h2></h2>
            <ol class="breadcrumb">
                <li >用户中心</li>
                </li>
                <li class="active">密码修改</li>
            </ol><!-- .breadcrumb -->
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Default box -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <form class="form-horizontal" id="news_search">
                        <div class="form-group" style="margin-bottom: 5px">
                            <label class="control-label col-sm-3"><font color="#c00">*</font>原密码:</label>
                            <div class="col-sm-6">
                                <input type="password" id="oldPassword" name="number" class="form-control" placeholder="请输入原密码"  >
                            </div>

                        </div>
                        <div class="form-group" style="margin-bottom: 5px">
                            <label class="control-label col-sm-3"><font color="#c00">*</font>新密码:</label>
                            <div class="col-sm-6">
                                <input type="password" id="password1" name="number" class="form-control" placeholder="请输入新密码,6-20位数字字母组合" >
                            </div>

                        </div>
                        <div class="form-group" style="margin-bottom: 5px">
                            <label class="control-label col-sm-3"><font color="#c00">*</font>新密码确认:</label>
                            <div class="col-sm-6">
                                <input type="password" id="password2" name="number" class="form-control" placeholder="请再输入新密码,6-20位数字字母组合" >
                            </div>

                        </div>
                        <div class="form-group" style="margin-bottom: 5px">
                            <label class="control-label col-sm-3"></label>
                            <p class="col-sm-6" id="message" style="color: red"></p>

                        </div>
                    </form>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" id="btn-password-save"
                                data-loading-text="提交中...">保存</button>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="../page/footer.jsp"></jsp:include>
</div>

<script>

    $("#btn-password-save").click(function () {
        var $message = $("#message");
        $message.text("");
        var newPass1 = $("#password1").val();
        var newPass2 = $("#password2").val();
        var oldPass =  $("#oldPassword").val();
        var reg = /^[A-Za-z0-9]{6,20}$/;
        if(!reg.test(oldPass)){
            $message.text("请输入正确的原密码格式");
            return;
        }
        if(!reg.test(newPass1)){
            $message.text("密码格式错误，请输入正确的格式，6-20位数字字母组合");
            return;
        }
        if(newPass1!=newPass2){
            $message.text("新密码两个输入不一样");
            return;
        }
        $.post("/user/password",{oldPassword:oldPass,newPassword:newPass1},function (data) {
            if(data==1){
                success("修改成功，请重新登陆");
                window.location.href="/login";
            }
            if(data==0){
                $message.text("原密码错误");
            }
        });
    });

</script>
</body>
</html>